package com.fearless.demo04;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.omg.CORBA.PUBLIC_MEMBER;

import java.util.Date;

@Aspect
public class Aspect01 {

    @Pointcut("execution(* com.fearless.demo04.impl.*.*(..))")
    public void myPointCut(){};


    @Before("myPointCut()")//在我们执行目标方法之前运行(@Before)
    public void before(){
        System.out.println("前置通知"+new Date());
    }

    @After("myPointCut()")//后置通知:在我们目标方法运行结束之后 ,不管有没有异常(@After)
    public void after(){
        System.out.println("后置通知"+new Date());
    }


    @AfterReturning("myPointCut()")//返回通知:在我们的目标方法正常返回值后运行(@AfterReturning)
    public void returning(){
        System.out.println("方法正常结束奥");
    }


    @AfterThrowing("myPointCut()")//异常通知:在我们的目标方法出现异常后运行(@AfterThrowing)
    public void exception(){
        System.out.println("发生异常了奥，异常通知");
    }


    @Around("myPointCut()")//环绕通知:动态代理, 需要手动执行joinPoint.procced()。(@Around)
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前");
        Object proceed = joinPoint.proceed();//执行目标方法
        System.out.println("环绕后");

    }

}
